package cn.herlioner.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


import cn.herlioner.pojo.CRUObject;
import cn.herlioner.pojo.TSObject;
import cn.herlioner.service.CRUObjectService;
import cn.herlioner.pojo.Student;
import cn.herlioner.dao.ObjectDAO;
import cn.herlioner.dao.StudentDAO;
import cn.herlioner.dao.impl.ObjectDAOImpl;
import cn.herlioner.dao.impl.StudentDAOImpl;

public class Util extends ActionSupport implements SessionAware{
	Student student;
	List<TSObject> tSObjects;
	ObjectDAO objectDAO = new ObjectDAOImpl();
	StudentDAO studentDAO = new StudentDAOImpl();
	CRUObject cruObject;
	List<CRUObject> cruObjects;
	private String noticechange;
	private String noticefor;
	
	public String getNoticefor() {
		return noticefor;
	}
	public void setNoticefor(String noticefor) {
		this.noticefor = noticefor;
	}
	public String getNoticechange() {
		return noticechange;
	}
	public void setNoticechange(String noticechange) {
		this.noticechange = noticechange;
	}
	public List<CRUObject> getCruObjects() {
		return cruObjects;
	}
	public void setCruObjects(List<CRUObject> cruObjects) {
		this.cruObjects = cruObjects;
	}
	public CRUObject getCruObject() {
		return cruObject;
	}
	public void setCruObject(CRUObject cruObject) {
		this.cruObject = cruObject;
	}
	public ObjectDAO getObjectDAO() {
		return objectDAO;
	}
	public void setObjectDAO(ObjectDAO objectDAO) {
		this.objectDAO = objectDAO;
	}
	public List<TSObject> getObjects() {
		return tSObjects;
	}
	public void setObjects(List<TSObject> tSObjects) {
		this.tSObjects = tSObjects;
	}
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}
	public StudentDAO getStudentDAO() {
		return studentDAO;
	}
	public void setStudentDAO(StudentDAO studentDAO) {
		this.studentDAO = studentDAO;
	}
	/**
	 * 重定向首�?
	 * @return
	 */
	public String turnhomepage(){
		return "success";
	}
	/**
	 * 重定向�?课页�?
	 */
	public String turnselectobj(){
		tSObjects = objectDAO.list();
		return "success";
	}
	/**
	 * 重定向学生信息修�?
	 */
	public String turntostudentupdatepage(){
		student = studentDAO.get(student.getStunum());
		Map session = ActionContext.getContext().getSession();
		session.put("student", student);
		return "success";
	}
	/**
	 * 重定向课程信息修�?
	 * 根据request域中的objnum值与session中得CRUObjects的CRUObject对象的objnum值相比较，对objnum值相同的CRUObject对象进行修改
	 * @return
	 */
	public String turntoobjectupdatepage(){
		Long objnum = cruObject.getObjnum();
		HttpServletRequest request = ServletActionContext.getRequest();
		CRUObject cruObject = new CRUObject();
		CRUObjectService cruObjectService = new CRUObjectService();
		cruObject = cruObjectService.setobjselct(objnum, cruObject);
		request.setAttribute("CRUObject", cruObject);
		return "success";
	}
	public String turntostudentaddpage(){
		return "success";
	}
	public String turntoaddteacherpage(){
		return "success";
	}
	
	/**
	 * 修改通告
	 * @return
	 */
	public String notice(){
		return "success";
	}
	
	/**
	 * 读取公告
	 * @return
	 */
	public String getnotice(){
		Map session = ActionContext.getContext().getSession();
		session.put("notice", noticefor);
		return "success";
	}
	
	@Override
	public void setSession(Map<String, java.lang.Object> arg0) {
		// TODO Auto-generated method stub
		
	}
	
	
}
